<include file="Flow:header"/>
<body>
    <div class="wraper">
        <div class="head clearfix">
            <a href="javascript:history.back(-1)" class="iconfont icon-zuojiantou pull-left"></a>
            <span class="head-name pull-left">完善信息</span>
        </div>
        <div class="form-box">
            <div class="form-list tb-mode">
                <p class="field tb-cell">真实姓名</p>
                <p class="area tb-cell" id="real_name">{BEESCRM:$isUser['real_name']}</p>
            </div>
            <div class="form-list tb-mode">
                <p class="field tb-cell">手机号码</p>
                <p class="area tb-cell"><input placeholder="请输入您的手机号码"  value="{BEESCRM:$isUser['mobile']}" type="tel" id="mobile"/></p>
            </div>
            <div class="form-list">
                <select id="optionNum">
                    <option value="2" <if condition="$isStatus eq 2">selected</if> >身份证号码</option>
                    <option value="1" <if condition="$isStatus eq 1">selected</if> >SIM卡服务密码</option>
                </select>
                <span class="iconfont icon-wodedingdan18"></span>
            </div>
            <div class="form-list">
                <input type="text" placeholder="请输入身份证号码" value="{BEESCRM:$password}" id="password"/>
                <input type="hidden" value="{BEESCRM:$isStatus}" id="isOptionNum">
            </div>
        </div>
        <p class="text-red" id="explain" style="padding: 10px"> *仅限于为本人名下手机办理此移动预缴费业务</p>
        <a class="normal-btn" id="addInfo">确认提交</a>
    </div>

    <div class="pop-box" id="infoSorry">
        <div class="main">
            <p class="iconfont icon-chenggong"></p>
            <div class="main-text">
                <p class="text-center">数据异常</p>
            </div>
        </div>
    </div>

    <div class="pop-box" style="display: none">
        <div class="main">
            <p class="iconfont icon-chenggong"></p>
            <div class="main-text">
                <p class="stress text-center">申请已提交</p>
                <p class="text-center">您已预约成功，请等待工作人员与您联系</p>
            </div>
        </div>
    </div>
    <input type="hidden" value="{BEESCRM:$conf_id}" id="conf_id">
    <input type="hidden" value="{BEESCRM:$isFlowUser['userinfo_id']}" id="userinfo_id">
    <input type="hidden" value="{BEESCRM:$orderId}" id="order_id">
    <input type="hidden" value="{BEESCRM:$isStatus}" id="isStatus">
    <script src="/assets/base/flow/js/jquery-2.1.0.min.js"></script>
    <script src="/assets/bower_components/sweetalert/lib/sweet-alert.min.js"></script>
    <script src="/assets/base/flow/js/jq.utils.js"></script>
    <script>
        var isStatus = $('#isStatus').val();
        var optionNum = $("#optionNum").val();
        $("#mobile").attr("maxlength","11");
        if(optionNum == 1)
        {
            $("#password").attr("type","tel");
            $("#password").attr("maxlength","6");
        }
        else if(optionNum == 2)
        {
            $("#password").attr("maxlength","18");
        }
        $("#optionNum").bind('change',function()
        {
            var optionNum = $("#optionNum").val();
            if(optionNum == 1)
            {
                $("#password").attr("type","tel");
                $("#password").attr("maxlength","6");
                if(isStatus == 1){
                    $("#password").val({BEESCRM:$password});
                }else {
                    $("#password").val('');
                }
                $("#password").attr("placeholder","请输入SIM卡密码");
            }
            else if(optionNum == 2)
            {
                $("#password").attr("type",false);
                $("#password").attr("maxlength","18");
                if(isStatus == 2){
                    $("#password").val({BEESCRM:$password});
                }else {
                    $("#password").val('');
                }

                $("#password").attr("placeholder","请输入身份证号码");
            }
        });

        var conf_id = $("#conf_id").val();
        $("#addInfo").on('click', function ()
        {
            var mobile = $("#mobile").val();
            var password = $("#password").val();
            var optionNum = $("#optionNum").val();
            var name = $("#real_name").text();
            var orderId = $('#order_id').val();

            if (!mobile) {
                $('#infoSorry').find('.text-center').text('手机号码不能为空！');
                $("#infoSorry").show();
                setTimeout('$("#infoSorry").fadeOut()',1200);
                return false;
            }

            if (!$.trim(password)) {
                $('#infoSorry').find('.text-center').text('身份证号码或者SIM卡密码不能为空！');
                $("#infoSorry").show();
                setTimeout('$("#infoSorry").fadeOut()',1200);
                return false;
            }

            $.ajax({
                url:"/base/flow/checkuser/conf_id/"+conf_id,
                type:"post",
                dataType:"json",
                data:{mobile: mobile,name:name},
                success:function(msg)
                {
                    if(msg.status == 'F'){
                        $.alert('error',msg.message,4000);
                        return false;
                    }else {
                        $.ajax({
                            url: "/base/flow/doModifyUserInfo/conf_id/" + conf_id,
                            type: "post",
                            dataType: 'json',
                            async: true,
                            data: {
                                mobile: mobile,
                                password: password,
                                optionNum: optionNum,
                                name: name,
                                order_id: orderId
                            },
                            success: function (data)
                            {
                                if (data.err_code == 200)
                                {
                                    setTimeout('jumpurl()', 1500);
                                } else if (data.err_code == 10000)
                                {
                                    $('#infoSorry').find('.text-center').text(data.message);
                                    $("#infoSorry").show();
                                    setTimeout('$("#infoSorry").fadeOut()',1200);
                                }
                            }
                        });
                    }
                }
            });

//            $.ajax({
//                url: "/base/flow/doModifyUserInfo/conf_id/" + conf_id,
//                type: "post",
//                dataType: 'json',
//                async: true,
//                data: {
//                   mobile: mobile,
//                   password: password,
//                   optionNum: optionNum,
//                   name: name,
//                   order_id: orderId
//               },
//                success: function (data)
//                {
//                    if (data.err_code == 200)
//                    {
//                        $('#infoPass').show();
//                        setTimeout('jumpurl()', 1500);
//                    } else if (data.err_code == 10000)
//                    {
//                        $('#infoSorry').find('.text-center').text(data.message);
//                        $("#infoSorry").show();
//                        setTimeout('$("#infoSorry").fadeOut()',1200);
//                    }
//                }
//            });
        });
        
//        var isOptionNum = $("#isOptionNum").val();
//        if (isOptionNum == 1)
//        {
//            $("#optionNum").val(1);
//        } else
//        {
//            $("#optionNum").val(2);
//        }
        
        function jumpurl() {
            var userInfoId = $('#userinfo_id').val();
            var userOrderStatus = "{BEESCRM:$orderStatus}";

            if (userInfoId) {
                if (userOrderStatus == 2 || userOrderStatus == 5 || userOrderStatus == 4) {
                    location.href = "/index.php?g=base&m=flow&a=showconfirminfo&conf_id=" + conf_id;
                } else {
                    location.href = "/index.php?g=base&m=flow&a=orderlist&conf_id=" + conf_id;
                }
            } else {
                location.href = "/index.php?g=base&m=flow&a=showconfirminfo&conf_id=" + conf_id;
            }

        }
    </script>
</body>
</html>
